package br.fatec.controle;

import java.io.IOException;

import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;

/**
 * SERVLET implementation class ServletControle
 */
@WebServlet("/ServletControle")
public class ServletControle extends HttpServlet {
	private static final long serialVersionUID = 1L;
	String mensagem = "";

	/**
	 * CONSTRUTOR default.
	 */
	public ServletControle() {
		super();
	}

	/**
	 * IMPLEMENTACAO DO METODO doGet.
	 * 
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		executa(request, response);
	}

	/**
	 * IMPLEMENTACAO DO METODO doPost.
	 * 
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		executa(request, response);
	}

	/**
	 * RECEBE A REQUISICAO DA CAMADA DE APRESENTACAO E SELECIONA A OPERACAO ADEQUADA.
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void executa(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String acao = request.getParameter("acao"); // CONTROLA A LOGICA DE APLICACAO
		/*if (acao.equals("FormLogin")) {
			this.login(request, response);
		}*/
		if (acao.equals("cadastraEmpresa")) {
			this.cadastrarEmpresa(request, response);
		}
	}

	/**
	 * CONTROLE DE ACESSO
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	/*public void login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String url = "";
		String achou = "false";
		UsuarioRepositorio repositorio = new UsuarioRepositorio();
		if (repositorio.login(request.getParameter("userName"),
				request.getParameter("password"))) {
			achou = "true";
			url = "../apresentacao/FormMenu.jsp";
		} else {
			achou = "false";
			url = "../apresentacao/FormLogin.jsp";
		}
		request.getRequestDispatcher(url).forward(request, response);
	}*/

	/**
	 * Cadastra Cliente
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void cadastrarEmpresa(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		/*ClienteRepositorio repositorio = new ClienteRepositorio();
		Cliente umCliente = new Cliente();
		try {
			umCliente.setCPF(request.getParameter("cpf"));
			umCliente.setNome(request.getParameter("nome"));
			umCliente.setEndereco(request.getParameter("endereco"));
			umCliente.setTelefone(request.getParameter("telefone"));
			mensagem = repositorio.cadastra(umCliente);
		} catch (Exception e) {
			mensagem = e.getMessage();
		}
		request.setAttribute("mensagem", mensagem);
		request.getRequestDispatcher("/visao/FormClienteCadastra.jsp").forward(request, response);
		*/
		System.out.println("cadastro");
		
	}



}
